package org.example.userservice.impl;

import org.example.context.BaseContext;
import org.example.mapper.AddressMapper;
import org.example.pojo.entity.AddressBook;
import org.example.userservice.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public List<AddressBook> list(AddressBook addressBook) {
        return addressMapper.list(addressBook);
    }

    @Override
    public void insert(AddressBook addressBook) {
        addressMapper.insert(addressBook);
    }

    @Override
    public void update(AddressBook address) {
        addressMapper.update(address);
    }

    @Override
    public void setDefault(int id) {
        AddressBook address = addressMapper.findById(id);
        address.setUserid(BaseContext.getCurrentId());
        addressMapper.setnodefault(address);
        addressMapper.setdefault(address);
    }
}
